package com.yangming.springboot.deepin.playTest;

import java.util.concurrent.TimeUnit;

/**
 * @创建人 ym
 * @创建时间 2021/4/8 0008
 * @描述
 **/
public class Join {

    public static void main(String[] args) throws Exception{
        Thread previous = Thread.currentThread(); //这里获取的是主线程
        for (int i=0;i <10; i++){
            Thread thread = new Thread(new Domino(previous), String.valueOf(i));
            thread.start();
            previous = thread;
        }
        TimeUnit.SECONDS.sleep(5);
        System.out.println(Thread.currentThread().getName() + "terminate end.");
    }

    public static class Domino implements Runnable{
        private Thread thread;
        public Domino(Thread thread){
            this.thread = thread;
        }
        @Override
        public void run(){
            try{
                thread.join();
            }catch(InterruptedException e){
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "terminate.");
        }
    }

}
